package com.woniuxy.Request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @auther linke
 * @create 2021-10-18 14:24
 */
@WebServlet("/requestDemo07")
public class RequestDemo07 extends HttpServlet {

    /**
     * request作用域三大方法测试
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置属性
        req.setAttribute("name","张三");
        //获取属性
        Object name = req.getAttribute("name");
        System.out.println(name);//张三
        //移除属性
        req.removeAttribute("name");

        Object name1 = req.getAttribute("name");
        System.out.println(name1);//null

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
